nodeData = [];
linkData = [];
// 连接的控件数据
var nodeDataChildArray = [];
// 连接的方向
var linkDataChildArray = [];
var inter;// 锁定当前选定的接口
var myobj;// 列出接口-所有类
function init() {
	var $ = go.GraphObject.make; // for conciseness in defining templates

	myDiagram = $(go.Diagram, "myDiagramDiv", // must name or refer to the DIV
	// HTML element
	{
		initialContentAlignment : go.Spot.Center,
		allowDrop : true, // must be true to accept drops from the Palette
		"LinkDrawn" : showLinkLabel, // this DiagramEvent listener is defined
		// below
		"LinkRelinked" : showLinkLabel,
		"animationManager.duration" : 800, // slightly longer than default
		// (600ms) animation
		"undoManager.isEnabled" : true
	// enable undo & redo
	});

	// when the document is modified, add a "*" to the title and enable the
	// "Save" button
	myDiagram.addDiagramListener("Modified", function(e) {
		var button = document.getElementById("SaveButton");
		if (button)
			button.disabled = !myDiagram.isModified;
		var idx = document.title.indexOf("*");
		if (myDiagram.isModified) {
			if (idx < 0)
				document.title += "*";
		} else {
			if (idx >= 0)
				document.title = document.title.substr(0, idx);
		}
	});

	// helper definitions for node templates

	function nodeStyle() {
		return [
				// The Node.location comes from the "loc" property of the node
				// data,
				// converted by the Point.parse static method.
				// If the Node.location is changed, it updates the "loc"
				// property of the node data,
				// converting back using the Point.stringify static method.
				new go.Binding("location", "loc", go.Point.parse)
						.makeTwoWay(go.Point.stringify), {
					// the Node.location is at the center of each node
					locationSpot : go.Spot.Center,
					// isShadowed: true,
					// shadowColor: "#888",
					// handle mouse enter/leave events to show/hide the ports
					mouseEnter : function(e, obj) {
						showPorts(obj.part, true);
					},
					mouseLeave : function(e, obj) {
						showPorts(obj.part, false);
					}
				} ];
	}

	// Define a function for creating a "port" that is normally transparent.
	// The "name" is used as the GraphObject.portId, the "spot" is used to
	// control how links connect
	// and where the port is positioned on the node, and the boolean "output"
	// and "input" arguments
	// control whether the user can draw links from or to the port.
	function makePort(name, spot, output, input) {
		// the port is basically just a small circle that has a white stroke
		// when it is made visible
		return $(go.Shape, "Circle", {
			fill : "transparent",
			stroke : null, // this is changed to "white" in the showPorts
			// function
			desiredSize : new go.Size(8, 8),
			alignment : spot,
			alignmentFocus : spot, // align the port on the main Shape
			portId : name, // declare this object to be a "port"
			fromSpot : spot,
			toSpot : spot, // declare where links may connect at this port
			fromLinkable : output,
			toLinkable : input, // declare whether the user may draw links
			// to/from here
			cursor : "pointer" // show a different cursor to indicate potential
		// link point
		});
	}

	// define the Node templates for regular nodes

	var lightText = 'whitesmoke';

	myDiagram.nodeTemplateMap.add("", // the default category
	$(go.Node, "Spot", nodeStyle(),
	// the main object is a Panel that surrounds a TextBlock with a rectangular
	// Shape
	$(go.Panel, "Auto", $(go.Shape, "Rectangle", {
		fill : "#00A9C9",
		stroke : null
	}, new go.Binding("figure", "figure")), $(go.TextBlock, {
		font : "bold 11pt Helvetica, Arial, sans-serif",
		stroke : lightText,
		margin : 8,
		maxSize : new go.Size(160, NaN),
		wrap : go.TextBlock.WrapFit,
		editable : true
	}, new go.Binding("text").makeTwoWay(),
	// 添加属性
	new go.Binding("inputparams").makeTwoWay(), new go.Binding("result")
			.makeTwoWay(), new go.Binding("classkey").makeTwoWay(),
			new go.Binding("methodkey").makeTwoWay()), {
		click : interfaceClick
	} // 显示接口属性
	),
	// four named ports, one on each side:
	makePort("T", go.Spot.Top, false, true), makePort("L", go.Spot.Left, true,
			true), makePort("R", go.Spot.Right, true, true), makePort("B",
			go.Spot.Bottom, true, false))

	);

	myDiagram.nodeTemplateMap.add("Start", $(go.Node, "Spot", nodeStyle(), $(
			go.Panel, "Auto", $(go.Shape, "Circle", {
				minSize : new go.Size(40, 40),
				fill : "#79C900",
				stroke : null
			}), $(go.TextBlock, "Start", {
				font : "bold 11pt Helvetica, Arial, sans-serif",
				stroke : lightText
			}, new go.Binding("text")),
			// 添加属性
			new go.Binding("className"), new go.Binding("methodName")
					.makeTwoWay(), new go.Binding("result").makeTwoWay(),
			// new go.Binding("classkey").makeTwoWay(),new
			// go.Binding("methodkey").makeTwoWay(),
			// 用户设置输入参数类型
			{
				mouseEnter : startClick
			}),
	// three named ports, one on each side except the top, all output only:
	makePort("L", go.Spot.Left, true, false), makePort("R", go.Spot.Right,
			true, false), makePort("B", go.Spot.Bottom, true, false)));

	myDiagram.nodeTemplateMap.add("End", $(go.Node, "Spot", nodeStyle(), $(
			go.Panel, "Auto", $(go.Shape, "Circle", {
				minSize : new go.Size(40, 40),
				fill : "#DC3C00",
				stroke : null
			}), $(go.TextBlock, "End", {
				font : "bold 11pt Helvetica, Arial, sans-serif",
				stroke : lightText
			}, new go.Binding("text")),
			// 添加属性
			new go.Binding("inputparams").makeTwoWay(),
			// new go.Binding("classkey").makeTwoWay(),new
			// go.Binding("methodkey").makeTwoWay(),
			// 用户设置输出结果类型
			{
				mouseEnter : endClick
			}),
	// three named ports, one on each side except the bottom, all input only:
	makePort("T", go.Spot.Top, false, true), makePort("L", go.Spot.Left, false,
			true), makePort("R", go.Spot.Right, false, true)));

	myDiagram.nodeTemplateMap.add("Comment", $(go.Node, "Auto", nodeStyle(), $(
			go.Shape, "File", {
				fill : "#EFFAB4",
				stroke : null
			}), $(go.TextBlock, {
		margin : 5,
		maxSize : new go.Size(200, NaN),
		wrap : go.TextBlock.WrapFit,
		textAlign : "center",
		editable : true,
		font : "bold 12pt Helvetica, Arial, sans-serif",
		stroke : '#454545'
	}, new go.Binding("text").makeTwoWay())
	// no ports, because no links are allowed to connect with a comment
	));

	// replace the default Link template in the linkTemplateMap
	myDiagram.linkTemplate = $(go.Link, // the whole link panel
	{
		routing : go.Link.AvoidsNodes,
		curve : go.Link.JumpOver,
		corner : 5,
		toShortLength : 4,
		relinkableFrom : true,
		relinkableTo : true,
		reshapable : true,
		resegmentable : true,
		// mouse-overs subtly highlight links:
		mouseEnter : function(e, link) {
			link.findObject("HIGHLIGHT").stroke = "rgba(30,144,255,0.2)";
		},
		mouseLeave : function(e, link) {
			link.findObject("HIGHLIGHT").stroke = "transparent";
		}

	}, new go.Binding("points").makeTwoWay(), $(go.Shape, // the highlight
	// shape, normally
	// transparent
	{
		isPanelMain : true,
		strokeWidth : 8,
		stroke : "transparent",
		name : "HIGHLIGHT"
	}), $(go.Shape, // the link path shape
	{
		isPanelMain : true,
		stroke : "gray",
		strokeWidth : 2
	}), $(go.Shape, // the arrowhead
	{
		toArrow : "standard",
		stroke : null,
		fill : "gray"
	}), $(go.Panel, "Auto", // the link label, normally not visible
	{
		visible : false,
		name : "LABEL",
		segmentIndex : 2,
		segmentFraction : 0.5
	}, new go.Binding("visible", "visible").makeTwoWay(), new go.Binding(
			"condition").makeTwoWay(), $(go.Shape, "RoundedRectangle", // the
																		// label
																		// shape
	{
		fill : "#F8F8F8",
		stroke : null
	}), $(go.TextBlock, "判断条件", // the label
	{
		textAlign : "center",
		font : "10pt helvetica, arial, sans-serif",
		stroke : "#333333",
		editable : true
	}, new go.Binding("text").makeTwoWay())), {
		mouseEnter : linkClick
	}// click even for link to show the third div--myParameterDiv

	);

	// Make link labels visible if coming out of a "conditional" node.
	// This listener is called by the "LinkDrawn" and "LinkRelinked"
	// DiagramEvents.
	function showLinkLabel(e) {
		var label = e.subject.findObject("LABEL");
		if (label !== null)
			label.visible = (e.subject.fromNode.data.figure === "Diamond");
	}

	// temporary links used by LinkingTool and RelinkingTool are also
	// orthogonal:
	myDiagram.toolManager.linkingTool.temporaryLink.routing = go.Link.Orthogonal;
	myDiagram.toolManager.relinkingTool.temporaryLink.routing = go.Link.Orthogonal;

	load(); // load an initial diagram from some JSON text

	// initialize the Palette that is on the left side of the page
	myPalette = $(go.Palette, "myPaletteDiv", // must name or refer to the DIV
	// HTML element
	{
		"animationManager.duration" : 800, // slightly longer than default
		// (600ms) animation
		nodeTemplateMap : myDiagram.nodeTemplateMap, // share the templates
		// used by myDiagram
		model : new go.GraphLinksModel([ // specify the contents of the
		// Palette
		{
			category : "Start",
			text : "Start"
		}, {
			text : "Step"
		}, {
			text : "Frok",
			figure : "Diamond"
		}, {
			category : "End",
			text : "End"
		}, {
			category : "Comment",
			text : "Comment"
		} ])
	});
	myParameter = $(go.Diagram, "myParameterDiv", {
		initialContentAlignment : go.Spot.Center,
		validCycle : go.Diagram.CycleNotDirected, // don't allow loops
		// For this sample, automatically show the state of the diagram's model
		// on the page
		"ModelChanged" : function(e) {
			if (e.isTransactionFinished)
				showModel();
		},
		"undoManager.isEnabled" : true
	});
	// This template is a Panel that is used to represent each item in a
	// Panel.itemArray.
	// The Panel is data bound to the item object.
	var fieldTemplate = $(go.Panel, "TableRow", // this Panel is a row in the
	// containing Table
	new go.Binding("portId", "name"), // this Panel is a "port"
	{
		background : "transparent", // so this port's background can be picked
		// by the mouse
		fromSpot : go.Spot.Right, // links only go from the right side to the
		// left side
		toSpot : go.Spot.Left,
		// allow drawing links from or to this port:
		fromLinkable : true,
		toLinkable : true
	}, $(go.Shape, {
		width : 12,
		height : 12,
		column : 0,
		strokeWidth : 2,
		margin : 4,
		// but disallow drawing links from or to this shape:
		fromLinkable : false,
		toLinkable : false
	}, new go.Binding("figure", "figure"), new go.Binding("fill", "color")), $(
			go.TextBlock, {
				margin : new go.Margin(0, 5),
				column : 1,
				font : "bold 13px sans-serif",
				alignment : go.Spot.Left,
				// and disallow drawing links from or to this text:
				fromLinkable : false,
				toLinkable : false
			}, new go.Binding("text", "name")), $(go.TextBlock, {
		margin : new go.Margin(0, 5),
		column : 2,
		font : "13px sans-serif",
		alignment : go.Spot.Left
	}, new go.Binding("text", "info")));

	// This template represents a whole "record".
	myParameter.nodeTemplate = $(go.Node, "Auto", {
		movable : false,
		copyable : false,
		deletable : false
	}, new go.Binding("location", "loc", go.Point.parse)
			.makeTwoWay(go.Point.stringify),
	// this rectangular shape surrounds the content of the node
	$(go.Shape, {
		fill : "#EEEEEE"
	}),
	// the content consists of a header and a list of items
	$(go.Panel, "Vertical",
	// this is the header for the whole node
	$(go.Panel, "Auto", {
		stretch : go.GraphObject.Horizontal
	}, // as wide as the whole node
	$(go.Shape, {
		fill : "#1570A6",
		stroke : null
	}), $(go.TextBlock, {
		alignment : go.Spot.Center,
		margin : 3,
		stroke : "white",
		textAlign : "center",
		font : "bold 12pt sans-serif"
	}, new go.Binding("text", "text"))),///原本为key
	// this Panel holds a Panel for each item object in the itemArray;
	// each item Panel is defined by the itemTemplate to be a TableRow in this
	// Table
	$(go.Panel, "Table", {
		padding : 2,
		minSize : new go.Size(100, 10),
		defaultStretch : go.GraphObject.Horizontal,
		itemTemplate : fieldTemplate
	}, new go.Binding("itemArray", "fields")) // end Table Panel of items
	) // end Vertical Panel
	); // end Node

	myParameter.linkTemplate = $(go.Link, {
		relinkableFrom : true,
		relinkableTo : true, // let user reconnect links
		toShortLength : 4,
		fromShortLength : 2
	}, $(go.Shape, {
		strokeWidth : 1.5
	}), $(go.Shape, {
		toArrow : "Standard",
		stroke : null
	})

	);

	myParameter.model = new go.GraphLinksModel(nodeDataChildArray,
			linkDataChildArray);
	myParameter.model.linkFromPortIdProperty = "fromPort";
	myParameter.model.linkToPortIdProperty = "toPort";
	showModel(); // show the diagram's initial model

	function showModel() {
		document.getElementById("mySavedModel2").textContent = myParameter.model
				.toJson();

	}
	selectInit();
	
}

// 点击连线触发的事件
function linkClick(e, point) {
	inter = point.je;
	var fromid = point.je.from;
	var toid = point.je.to;
	var linkedId = fromid + " --> " + toid;
	var from;
	var to;
	// 从nodeData linkData对象中获取连接的接口
	for (var i = 0; i < nodeData.length; i++) {
		if (nodeData[i].key == fromid) {
			from = nodeData[i];
		}
		if (nodeData[i].key == toid) {
			to = nodeData[i];
		}
	}
	if(from.result==null||from.result.length<1){
		from.result=[{'name':'noparam','type':'noparam'}];////////后期改正
	}

		
	
	if(to.inputparams==null||to.inputparams.length<1){
		to.inputparams=[{'name':'noparam','type':'noparam'}];////////后期改正
	}
	// to是否为判断框 /////////////////////用户不可在前一个判断没连接正常接口的情况下连接判断
	if (to.figure == "Diamond") {
		to.result = from.result;
		to.inputparams = from.result; // 判断框输入参=输出参
		to.classkey = from.classkey;
		to.methodkey = from.methodkey;
		to.className=from.className;
		to.methodName=from.methodName;
	}
	var fromFields = from.result;
	var toFields = to.inputparams;

	nodeDataChildArray = [ {
		key : fromid,
		fields : fromFields[0].name,//fromFields
		text:from.result[0].type,
		loc : "0 70"
	}];
	var name=toFields[0].name;
		nodeDataChildArray.push({
			key : toid,
//			fields : toFields[0].name,
			fields :name,//[{'paramName':'abc','type':'int'},{'paramName':'aaa','type':'float'}],
			text:to.inputparams[0].type,
			loc : "250 0"
		} );
	
	// linkDataChildArray = [];
	myParameter.model = new go.GraphLinksModel(nodeDataChildArray,
			linkDataChildArray);
	myParameter.model.linkFromPortIdProperty = "fromPort";
	myParameter.model.linkToPortIdProperty = "toPort";
	// from是否为判断框 --->添加条件
	if (from.figure == "Diamond") {
		// TextBlock
		document.getElementById("properties").innerHTML = "<p>"
				+ linkedId
				+ "</p>判断条件：<textarea id='condition' style='width:100%;height:100%'></textarea>"
				+ "<br/><button onclick='saveCondition()'>保存判断条件</button>";
		if (point.je.condition == null) {
			point.je.condition = from.text;
		}
		document.getElementById("condition").value = point.je.condition;
	} else {
		document.getElementById("properties").innerHTML = "<p>" + linkedId+ "</p>";
	}
	// 隐藏select
	document.getElementById("methodData").style.display = "none";
	document.getElementById("classData").style.display = "none";
	$("#divForStart").hide();
	$("#divForEnd").hide();
}
function saveCondition() {
	inter.condition = document.getElementById("condition").value;
}
// 从后台获取的接口数据
function selectInit() {
	// 获取class及method
	var jqxhr = jQuery.get("draw/getAllClass.do").done(
			function(data) {
				myobj = eval(data);
				console.log(myobj);
				// 加载classData的下拉列表
				var option = null;
				for (var i = 0; i < myobj.length; i++) {
					document.getElementById("classData").options
							.add(new Option(myobj[i].className, i));
				}
			}).fail(function() {
		alert("init flow model error");
	});
	/*
	 * myobj = [ { "className" : "Address", "method" : [ { "name" :
	 * "getAddress", "inputparams" : [ { "name" : " ", "type" : " " } ],
	 * "result" : [ { "name" : "address", "type" : "String" } ] }, { "name" :
	 * "setAddress", "inputparams" : [ { "name" : "address", "type" : "String" }, {
	 * "name" : "name", "type" : "String" } ], "result" : [ { "name" :
	 * "address", "type" : "String" } ]
	 *  } ] } ];
	 */
}

// 列出接口-选择的类-所有方法
function selectOnChange() {
	// 加载methodData的下拉列表
	var classIndex = document.getElementById("classData").value;
	var option2 = null;
	// 清空该下拉列表
	document.getElementById("methodData").options.length = 0;
	// 方法名称、参数、返回类型myobj[classIndex].method.length
	var methodlist = myobj[classIndex].method;
	for (var j = 0; j < methodlist.length; j++) {
		if (methodlist[j].result != null && methodlist[j].result.length > 0) {
			var inputparams = "";
			if (methodlist[j].inputparams != null
					&& methodlist[j].inputparams.length > 0) {
				for (var i = 0; i < methodlist[j].inputparams.length; i++) {
					if (inputparams != "") {
						inputparams = inputparams + ", ";
					}
					inputparams = inputparams
							+ methodlist[j].inputparams[i].type + " "
							+ methodlist[j].inputparams[i].name;
				}
			}
			document.getElementById("methodData").options.add(new Option(
					methodlist[j].result[0].type + " " + methodlist[j].name
							+ "(" + inputparams + ")", j));
		}
	}
	inter.classkey = document.getElementById("classData").value;
	inter.className = myobj[classIndex].className;
	// 默认方法选择
	inter.methodkey = document.getElementById("methodData").value;
	inter.methodName =methodlist[inter.methodkey].name;
	inter.inputparams = myobj[inter.classkey].method[inter.methodkey].inputparams;
	inter.result = myobj[inter.classkey].method[inter.methodkey].result;
}
// 更改方法----将接口的具体选择赋值给当前接口控件
function select2OnChange() {
	inter.methodkey = document.getElementById("methodData").value;
	inter.methodName =myobj[inter.classkey].method[inter.methodkey].name;
	inter.inputparams = myobj[inter.classkey].method[inter.methodkey].inputparams;
	inter.result = myobj[inter.classkey].method[inter.methodkey].result;
}
// 保存用户设置的开始和结束参数
function saveCircle() {
	if (inter.category == "Start") {
		// "开始"的参数属性设为result(对于link来讲)
		var type = document.getElementById("resultType").value;
		inter.result.splice(0, inter.result.length);// 清空之前数据
		inter.result.push({
			"type" : type,
			"name" : []
		});
		var  arr=$('#dg').datagrid('getRows'); 
	  	 for (var int = 0; int < arr.length; int++) {
	  		 if(!arr[int].isNewRecord){///////////////////////////////////需添加一行
//	  		 arr[int].isNewRecord=false;
	  		 inter.result[0].name.push({'name':arr[int].paramName,'type':arr[int].type});
	  	}}
		inter.className = document.getElementById("className").value;
		inter.methodName = document.getElementById("methodName").value;
	} else {
		// "结束"的参数属性设为inputparams(对于link来讲)
		var type = document.getElementById("inputType").value;
		inter.inputparams.splice(0, inter.inputparams.length);// 清空之前数据
		var  arr=$('#dg2').datagrid('getRows'); 
		var name=[];
	  	 for (var int = 0; int < arr.length; int++) {
	  		 if(!arr[int].isNewRecord){///////////////////////////////////需添加一行
	  		 name.push({'name':arr[int].paramName,'type':arr[int].type});
	  	}}
	  	inter.inputparams.push({
			"type" : type,
			"name" : name
		});
	}
	
}
// 显示接口属性
function interfaceClick(e, point) {
	inter = point.Xg.je;
	var inputparams = "";
	// 方法名称、参数、返回类型
	if (inter.classkey != "" && inter.methodkey != ""
			&& (inter.result != null && inter.result.length > 0)) {
		if (inter.inputparams != null && inter.inputparams.length > 0) {
			for (var i = 0; i < inter.inputparams.length; i++) {
				if (inputparams != "") {
					inputparams = inputparams + ", ";
				}
				inputparams = inputparams + inter.inputparams[i].type + " "
						+ inter.inputparams[i].name;
			}
		}
		document.getElementById("properties").innerHTML = "<p style='width:100%;height:100%'>"
				+ "<b>Interface Name:</b>  "
				+ inter.key
				+ "<br/> <b>inputparams:</b>      "
				+ inputparams
				+ "<br/><b> result:</b>          "
				+ inter.result[0].type
				+ "</p>";
		document.getElementById("classData").value = inter.classkey;
		document.getElementById("methodData").value = inter.methodkey;

	} else {
		document.getElementById("classData").value = "";
		document.getElementById("methodData").value = "";
		document.getElementById("properties").innerHTML = "<p style='width:100%;height:100%'>"
				+ "Interface Name:" + inter.key;
	}
	// 接口被选中时，属性div显示属性及接口具体的选择
	document.getElementById("classData").style.display = "inline";
	document.getElementById("methodData").style.display = "inline";
	$("#divForStart").hide();
	$("#divForEnd").hide();
}
function startClick(e, point) {
	inter = point.Xg.je;
	// 初始化“开始”参数
	if (inter.result == null || inter.result.length < 0) {
		inter.result = [ {
			"type" : "void",
			"name" : []
		} ];
	}
	
	if (inter.methodName == null) {
		inter.methodName = "demoMethod";
	}
	if (inter.className == null) {
		inter.className = "DemoClass";
	}

	document.getElementById("properties").innerHTML = "<button onclick='saveCircle()'>保存输入参数</button>"
		    + "<br/><b>接口：</b>" + "<input id='className' type='text'/>" 
		    + "<br/><b>方法：</b>" + "<input id='methodName' type='text'/>"
	        + "<br/><b>入参类型：</b>"+ "<input id='resultType' type='text' />" 
	        + "<br/><b>入参属性列表：</b>" ;
	document.getElementById("resultType").value = inter.result[0].type;
	document.getElementById("className").value = inter.className;
	document.getElementById("methodName").value = inter.methodName;
	// ”开始“被选中时，属性div隐藏
	document.getElementById("classData").style.display = "none";
	document.getElementById("methodData").style.display = "none";
	$("#divForStart").show();
	$("#divForEnd").hide();
}
function endClick(e, point) {
	inter = point.Xg.je;
	// 初始化“结束”参数
	if (inter.inputparams == null || inter.inputparams.length < 0) {
		inter.inputparams = [ {
			"name" : [],
			"type" : "void"
		} ];
	}
	document.getElementById("properties").innerHTML ="<button onclick='saveCircle()' >保存输出参数</button>"
		    + "<br/><b>出参类型：</b>"
			+ "<input id='inputType' type='text' style='width:100%;height:100%'/>"
			+ "<br/><b>出参列表：</b>";
	// ”结束“被选中时，属性div隐藏
	document.getElementById("inputType").value = inter.inputparams[0].type;
//	document.getElementById("inputName").value = inter.inputparams[0].name;
	document.getElementById("classData").style.display = "none";
	document.getElementById("methodData").style.display = "none";
	$("#divForStart").hide();
	$("#divForEnd").show();
}
function showPorts(node, show) {
	var diagram = node.diagram;
	if (!diagram || diagram.isReadOnly || !diagram.allowLink)
		return;
	node.ports.each(function(port) {
		port.stroke = (show ? "white" : null);
	});
}

// Show the diagram's model in JSON format that the user may edit
function save() {
	/*
	 * var tmpjson = myDiagram.model.toJson();
	 * document.getElementById("mySavedModel").value = myDiagram.model.toJson();
	 * myDiagram.isModified = false; alert(tmpjson);
	 */
	// tmpjson = $.parseJson(tmpjson);
	var text = myParameter.model.toJson();
	test = {
		"nodeDataArray" : nodeData,
		"linkDataArray" : linkData,
		"nodeDataChildArray" : nodeDataChildArray,
		"linkDataChildArray" : linkDataChildArray
	}
	console.log(test);
	var params = JSON.stringify(test);
	console.log(params);
	var jqxhr = jQuery.post("draw/generateCode.do", {
		"graph" : params
	}).done(function(data) {
		jQuery("#sourceRuleView").html(data);
	}).fail(function() {
		alert("error");
	});
}
// 加载模板图表代码
function loadModelMian() {
	myDiagram.model = go.Model.fromJson(document
			.getElementById("logicdatamain").value);
	// myDiagram.model = new go.GraphLinksModel(nodeData, linkData);
}
// 加载模板图表代码
function loadModelFrok1() {
	myDiagram.model = go.Model.fromJson(document
			.getElementById("logicdataFrok1").value);
	// myDiagram.model = new go.GraphLinksModel(nodeData, linkData);
}
// 加载模板图表代码
function loadModelFrok2() {
	myDiagram.model = go.Model.fromJson(document
			.getElementById("logicdataFrok2").value);
	// myDiagram.model = new go.GraphLinksModel(nodeData, linkData);
}
// 从后台获取初始化数据
function load() {

	var data = {
		"class" : "go.GraphLinksModel",
		"linkFromPortIdProperty" : "fromPort",
		"linkToPortIdProperty" : "toPort"
	};
	document.getElementById("mySavedModel").value = JSON.stringify(data);
	myDiagram.model = go.Model
			.fromJson(document.getElementById("mySavedModel").value);
	myDiagram.model = new go.GraphLinksModel(nodeData, linkData);
}

window.freshMapperView = function() {
	if (nodeDataChildArray.length != null && nodeDataChildArray.length > 0) {
		myParameter.model = new go.GraphLinksModel(nodeDataChildArray,
				linkDataChildArray);
		myParameter.model.linkFromPortIdProperty = "fromPort";
		myParameter.model.linkToPortIdProperty = "toPort";
	}

}

window.freshFlowView = function() {
	freshMapperView();
}
function doTabSelected(title, index) {
	if (index != 1) {
		return;
	}
	if (window.freshFlowView != null) {
		window.freshFlowView();
	}
}
$(function(){
	$("#divForStart").hide();
	$("#divForEnd").hide();
	
	//开始参数列表
    $('#dg').edatagrid({});
  

   //结束参数列表
    $('#dg2').edatagrid({});

});